package tcu.ead2021.utils;

import tcu.ead2021.entity.R;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MySQLUtils {

    public static void LoginUser(String username, String password) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = JDBCUtils.getConnection();
            String sql = "SELECT * FROM user WHERE username = ? AND password = ?";
            pstmt = conn.prepareStatement(sql);

            pstmt.setString(1, username);
            pstmt.setString(2, password);

            rs = pstmt.executeQuery();
            while (rs.next()){
                System.out.println("username："+rs.getString("username"));
                System.out.println("password："+rs.getString("password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //7、释放资源
            JDBCUtils.release(conn, pstmt, rs);
        }
    }
}
